#include <iostream>
using namespace std;
string s1,s2;
int n1,n2;
int ans[1005][1005];
int main(){
	cin>>s1>>s2;
	n1=s1.size();n2=s2.size();
	for(int i=1;i<=n1;++i){
		for(int j=1;j<=n2;++j){
			if(s1[i-1]==s2[j-1])ans[i][j]=ans[i-1][j-1]+1;
			else ans[i][j]=max(ans[i-1][j],ans[i][j-1]);
		}
	}
	cout<<ans[n1][n2]<<endl;
	return 0;
}
